package com.oritsh.dicom.utils;

import org.dcm4che.data.Attributes;
import org.dcm4che.io.DicomEncodingOptions;
import org.dcm4che.io.DicomInputStream;
import org.dcm4che.io.DicomOutputStream;
import org.dcm4che.net.PDVInputStream;
import org.dcm4che.util.SafeClose;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: zarra
 * Date: 14-2-10
 * Time: 下午1:20
 * Copyright Shanghai Orient Rain Information Technology Co.,Ltd.
 */
public class DicomStreamHelper {
    public static void writeToStream(DicomOutputStream out, Attributes fmi, PDVInputStream data) throws IOException {
        out.writeFileMetaInformation(fmi);
        data.copyTo(out);
        out.flush();
    }

    public static void writeToStream(DicomInputStream in,DicomOutputStream out) throws IOException {
        Attributes fmi = in.readFileMetaInformation();
        Attributes ds  = in.readDataset(-1,-1);

        DicomEncodingOptions encOpts = DicomEncodingOptions.DEFAULT;
        out.setEncodingOptions(encOpts);

        out.writeDataset(fmi,ds);

        out.flush();
    }
}
